# -*- coding: utf-8 -*-
# @Date    : 2015-06-21 15:50:35
# @Author  : Your Name (you@example.org)
# @Link    : http://example.org
# @Version : $Id$

from lib.tornado_routes import route
from web.handler import BaseHandler
from tornado import gen
from tornado.web import asynchronous
from decorator.auth import admin_login_required, admin_auth
import time
from web.models.admin.food.book import Boox
from lib.libpage import start as pagestart

@route(r'/admin/food/bookbox/?')
class IndexHandler(BaseHandler):
    @asynchronous
    @gen.coroutine
    def get(self):
        model =Boox()
        cur_page = self.get_argument('page', default=1)
        # start = pagestart(cur_page, self.offset)     
        # end=self.offset
        rest = yield model.list()

        ret=rest['ret']
        # count=rest['count']['count']

        # page_info={'total':int(count), 'page':int(cur_page)}

        self.render("admin/food/book/list.html",restlist=ret)

#处理搜索
@route(r'/admin/food/booksearch/?')
class IndexsearchHandler(BaseHandler):
    @asynchronous
    @gen.coroutine
    def post(self):
        model = Boox()
        
        Fuser_phone=self.get_argument('Fuser_phone',default=1)
        Fstatus=self.get_argument('Fstatus',default=1)
        rest=yield model.listsr(Fuser_phone,Fstatus)
        if rest !=-1:
            
            self.render("admin/food/book/list.html",restlist=rest)
        else:
            self.redirect("/admin/food/bookbox/")

#处理记录状态
@route(r'/admin/food/book/status/?')
class StatusHandler(BaseHandler):
    @asynchronous
    @gen.coroutine
    def get(self):
        model = Boox()
        Fstatus=self.get_argument('Fstatus',default=1)
        Fid=self.get_argument('Fid',default=1)
        rest=yield model.status(Fid,Fstatus)

        if rest:
             self.redirect("/admin/food/bookbox/")


@route(r'/admin/food/bookbox/new/?')
class NewHandler(BaseHandler):
    @asynchronous
    @gen.coroutine
    def get(self):
        self.render("admin/food/bookbox/new.html",)

